
package ui.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import net.ck.hzq.R;

import java.util.ArrayList;
import java.util.List;

import base.BaseViewHolder;
import base.SuperBaseAdapter;
import ui.model.RankingBean;


/**
 * 排行榜适配器
 * Created by chenjian on 19/2/27.
 */
public class RankingAdapter extends SuperBaseAdapter<RankingBean.ListBean> {

    List<RankingBean.ListBean> mData = new ArrayList<>();
    Context mContext;
    int mType = 1;

    public RankingAdapter(Context context, List<RankingBean.ListBean> data, int type) {
        super(context, data);
        mContext = context;
        mData = data;
        mType = type;
    }

    @Override
    protected void convert(BaseViewHolder holder, final RankingBean.ListBean item, final int position) {
        holder.setText(R.id.item_ranking_name, item.getCustomName());
        if (mType == 1) {
            holder.setText(R.id.item_ranking_money, item.getValue() + "万元");
        } else {
            holder.setText(R.id.item_ranking_money, item.getValue() + "台");
        }
        ImageView bg = holder.getView(R.id.item_ranking_image);
        TextView pos = holder.getView(R.id.item_ranking_number);
        int posT = position + 1;
        if (position == 0) {
            bg.setVisibility(View.VISIBLE);
            bg.setBackgroundResource(R.mipmap.top_one);
            pos.setText("TOP 1");
        } else if (position == 1) {
            bg.setVisibility(View.VISIBLE);
            bg.setBackgroundResource(R.mipmap.top_two);
            pos.setText("TOP 2");
        } else if (position == 2) {
            bg.setVisibility(View.VISIBLE);
            bg.setBackgroundResource(R.mipmap.top_three);
            pos.setText("TOP 3");
        } else {
            bg.setVisibility(View.INVISIBLE);
            bg.setBackgroundResource(R.mipmap.top_three);
            pos.setText("NO." + posT + "  ");
        }

    }


    @Override
    protected int getItemViewLayoutId(int position, RankingBean.ListBean item) {
        return R.layout.item_ranking;
    }

}
